<?php
include_once('services.filesystem.php');

session_start();

@$fuuid = $_REQUEST['fuuid'];

if(empty($fuuid))
    die('File not found!');

$fs = new FileSystem(CONFIG_FILE);
try
{
    if(!$fs->isWhitelisted($fuuid) && $_SESSION['id_utp_usr']!=_USERTYPE_ADMIN)
        die('No tiene permisos para ver el archivo!');
    
    $file_data = $fs->getFile($fuuid,true);
    
    $file['content']   = $file_data['content'];
    $file['mime-type'] = $file_data['mime_type'];
    $file['name']      = $file_data['filename'];
    $file['length']    = $file_data['length'];

    header('Content-Description: File Transfer');
    header('Content-Type:'. $file['mime-type']);
    header('Content-Disposition: attachment; filename='. $file['name'] );
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: '. $file['length']);
    ob_clean();
	flush();
    echo $file['content'];
}
catch(Exception $e)
{
    die("File Not Found!");
}

?>